#include <sstream>
#include "ros/ros.h"
#include "std_msgs/String.h"

int main(int argc,char **argv){
    // ROS节点初始
    ros::init(argc,argv,"talker");
    // 创建节点句柄
    ros::NodeHandle n;
    // 创建一个publiser.发布名为chatter的topic，消息泪下为std_msgs::string
    ros::Publisher chatter_pub = n.advertise<std_msgs::String> ("chartter",1000);
    ros::Rate loop_rate(10);

    int count = 0;
    while(ros::ok()){
        //初始化 std::msgs::String类型
        std_msgs::String msg;
        std::stringstream ss;
        ss<<"hello world"<<count;
        msg.data = ss.str();
        // 发布消息

        ROS_INFO("%s",msg.data.c_str());
        chatter_pub.publish(msg);
        // 循环等待回调函数
        ros::spinOnce();
        loop_rate.sleep();
        ++count;
    }
    return 0;
}